package com.ktg.common.utils.poi;

import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Data
@Accessors(chain = true)
public class ExcelTitle extends ExcelStyle{
    /**
     * 数据的类型
     */
    private Class<?> dataType = String.class;


    /**
     * 获取数据的名称，是map 中的key
     */
    private String dataName = "";


    /**
     * 设置某个cell
     */
    private Map<String,ExcelCell> rowStyle;


    private Map<Integer,IndexedColors> rowBackgroundColor;

    private Map<Integer,IndexedColors> rowTextColor;


    /* ------------------------------------------- 方法 ---------------------------------------- */
    public ExcelTitle(){

    }

    public ExcelTitle(String name,String dataName,Class<?> dataType){
        if (name != null){
            this.setName(name);
        }else {
            this.setName("");
        }
        if (dataName != null){
            this.dataName = dataName;
        }else {
            this.dataName = "";
        }

        this.dataType = dataType;
    }

    public ExcelTitle setRowStyle(List<ExcelCell> rowStyle) {
        HashMap map = new HashMap<>();
        for (ExcelCell excelCell : rowStyle){
            String key = excelCell.getRow()+":"+excelCell.getColumn();
            map.put(key,excelCell);

        }
        this.rowStyle = map;
        return this;
    }


    public ExcelTitle addRowStyle(ExcelCell cell) {
        if (this.rowStyle == null){
            this.rowStyle = new HashMap<>();
        }
        if (cell == null){
            return this;
        }
        String key = cell.getRow()+":"+cell.getColumn();
        this.rowStyle.put(key,cell);
        return this;
    }

    public ExcelTitle addRowColor(int row,IndexedColors backgroundColor,IndexedColors textColor) {
        if (this.rowBackgroundColor == null){
            this.rowBackgroundColor = new HashMap<>();
        }
        if (this.rowTextColor == null){
            this.rowTextColor = new HashMap<>();
        }
        if (backgroundColor != null){
            this.rowBackgroundColor.put(Integer.valueOf(row),backgroundColor);
        }
        if (textColor != null){
            this.rowTextColor.put(Integer.valueOf(row),textColor);
        }
        return this;
    }

}
